* APPENDIX C
cd "C:\Users\75618rpo\Dropbox\Research\Literature Latex\Corruption, accountability and voting\Submission R&R JoP\Replication\replication_package_JOP"
	global muni_controls lpib_pc gini illiteracy share_urb radio_am 	
	global mayor_controls male married age education prev_mayor share_vote_margin dum_PT		
	global challenger_controls male married age education prev_mayor dum_PT
	global cluster id_city

	global size_column "{p{5cm}p{1cm}p{1cm}p{1cm}p{1cm}p{1.5cm}p{1.5cm}c}"
	global format_table "vce(cluster $cluster) wide(mean1 sd1 mean2 sd2 diff pval) pvalues varlabels  format(%9.2f) nostars nonumbers noobservations nolines"
	
* Table C1
	use "data_brasil_camp.dta", clear
	tabstat camp_exp_pc if sample_camp_exp == 1, s(mean sd p25 median p75 p99 max) c(s) format (%6.2f)
 
	use "data_brasil_camp_chall.dta", clear
	tabstat camp_exp_pc if sample_camp_exp_chal == 1, s(mean sd p25 median p75 p99 max) c(s) format (%6.2f)
			
	
* Table C.2.
use "data_brasil_camp.dta", clear

preserve
	replace radio_am = 100 if radio_am == 1	/*so it is in %*/
	
	balancetable before broad fraction_broad using "tables and figures/table_c2a.tex", $format_table replace prehead("\begin{tabularx}{\linewidth} $size_column \textit{A. Reputation shocks} \\") postfoot("\end{tabularx}") 
	
	balancetable before $mayor_controls using "tables and figures/table_c2b.tex", $format_table replace prehead("\begin{tabularx}{\linewidth}  $size_column {\textit{B. Mayor characteristics}} \\") postfoot("\end{tabularx}") 

	balancetable before $muni_controls using "tables and figures/table_c2c.tex", $format_table replace prehead("\begin{tabularx}{\linewidth} $size_column {\textit{C. Municipal characteristics}} \\") postfoot("\end{tabularx}") 	
restore


* Table C.3
preserve
	keep if sample_camp_exp == 1 & above_median_corrupt == 1
	replace radio_am = 100 if radio_am == 1	
		
	balancetable before $mayor_controls using "tables and figures/table_c3a.tex", $format_table replace prehead("\begin{tabularx}{\linewidth}  $size_column {\textit{A. Mayor characteristics}} \\") postfoot("\end{tabularx}") 

	balancetable before $muni_controls using "tables and figures/table_c3b.tex", $format_table replace prehead("\begin{tabularx}{\linewidth} $size_column {\textit{B. Municipal characteristics}} \\") postfoot("\end{tabularx}") 	
restore

* Table C.4
preserve
	keep if sample_camp_exp == 1 & above_median_corrupt == 0
	replace radio_am = 100 if radio_am == 1	
	
	balancetable before $mayor_controls using "tables and figures/table_c4a.tex", $format_table replace prehead("\begin{tabularx}{\linewidth}  $size_column {\textit{A. Mayor characteristics}} \\") postfoot("\end{tabularx}") 

	balancetable before $muni_controls using "tables and figures/table_c4b.tex", $format_table replace prehead("\begin{tabularx}{\linewidth} $size_column {\textit{B. Municipal characteristics}} \\") postfoot("\end{tabularx}") 	
restore	

* Table C.5 
preserve
use "data_brasil_camp_chall.dta", clear

	keep if sample_camp_exp_chal == 1 & above_median_corrupt == 1
	replace radio_am = 100 if radio_am == 1	
		
	balancetable before $challenger_controls using "tables and figures/table_c5a.tex", $format_table replace prehead("\begin{tabularx}{\linewidth}  $size_column {\textit{A. Challenger characteristics}} \\") postfoot("\end{tabularx}") 

	balancetable before $muni_controls using "tables and figures/table_c5b.tex", $format_table replace prehead("\begin{tabularx}{\linewidth} $size_column {\textit{B. Municipal characteristics}} \\") postfoot("\end{tabularx}") 	
	
restore


* Table C.6 
preserve
use "data_brasil_camp_chall.dta", clear

	keep if sample_camp_exp_chal == 1 & above_median_corrupt == 0
	replace radio_am = 100 if radio_am == 1	
		
	balancetable before $challenger_controls using "tables and figures/table_c6a.tex", $format_table replace prehead("\begin{tabularx}{\linewidth}  $size_column {\textit{A. Challenger characteristics}} \\") postfoot("\end{tabularx}") 

	balancetable before $muni_controls using "tables and figures/table_c6b.tex", $format_table replace prehead("\begin{tabularx}{\linewidth} $size_column {\textit{B. Municipal characteristics}} \\") postfoot("\end{tabularx}") 	
	
restore



* Table C.7
use "data_brasil_camp.dta", clear

* incumbent
gen before_gini = before * gini
gen before_lpib_pc = before * lpib_pc
gen before_illiteracy = before * illiteracy

	label var before_gini "Before $\times$ gini"
	label var before_lpib_pc "Before $\times$ income"
	label var before_illiteracy "Before $\times$ illiteracy"
	
eststo clear	

		* gini
		eststo reg_median_c_gini: quietly areg camp_exp_pc before above_median_corrupt median_before before_gini $muni_controls $mayor_controls i.term, absorb(codigo_uf) robust  cluster($cluster)
				sum camp_exp_pc if e(sample), mean 
				loc mymean: display %9.3f r(mean) 	
				estadd local mD `mymean', replace	
				estadd local state_fe "\checkmark": reg_median_c_gini
				estadd local mayor_municipal "\checkmark": reg_median_c_gini
				lincom before + median_before
				local estimate: display %9.3f r(estimate)
				local p_test: display %9.3f r(p)
				estadd local b0_b2 `estimate': reg_median_c_gini
				estadd local p_value `p_test': reg_median_c_gini

		* pib
		eststo reg_median_c_pib: quietly areg camp_exp_pc before above_median_corrupt median_before before_lpib_pc $muni_controls $mayor_controls i.term, absorb(codigo_uf) robust  cluster($cluster)
				sum camp_exp_pc if e(sample), mean 
				loc mymean: display %9.3f r(mean) 	
				estadd local mD `mymean', replace	
				estadd local state_fe "\checkmark": reg_median_c_pib
				estadd local mayor_municipal "\checkmark": reg_median_c_pib
				lincom before + median_before
				local estimate: display %9.3f r(estimate)
				local p_test: display %9.3f r(p)
				estadd local b0_b2 `estimate': reg_median_c_pib
				estadd local p_value `p_test': reg_median_c_pib
		
		* illiteracy
		eststo reg_median_c_illi: quietly areg camp_exp_pc before above_median_corrupt median_before before_illiteracy $muni_controls $mayor_controls i.term, absorb(codigo_uf) robust  cluster($cluster)
				sum camp_exp_pc if e(sample), mean 
				loc mymean: display %9.3f r(mean) 	
				estadd local mD `mymean', replace	
				estadd local state_fe "\checkmark": reg_median_c_illi
				estadd local mayor_municipal "\checkmark": reg_median_c_illi
				lincom before + median_before
				local estimate: display %9.3f r(estimate)
				local p_test: display %9.3f r(p)
				estadd local b0_b2 `estimate': reg_median_c_illi
				estadd local p_value `p_test': reg_median_c_illi
				
		* all
		eststo reg_median_c_all: quietly areg camp_exp_pc before above_median_corrupt median_before before_gini before_lpib_pc before_illiteracy $muni_controls $mayor_controls i.term, absorb(codigo_uf) robust  cluster($cluster)
				sum camp_exp_pc if e(sample), mean 
				loc mymean: display %9.3f r(mean) 	
				estadd local mD `mymean', replace	
				estadd local state_fe "\checkmark": reg_median_c_all
				estadd local mayor_municipal "\checkmark": reg_median_c_all
				lincom before + median_before
				local estimate: display %9.3f r(estimate)
				local p_test: display %9.3f r(p)
				estadd local b0_b2 `estimate': reg_median_c_all
				estadd local p_value `p_test': reg_median_c_all
										
										

* challenger
preserve

use "data_brasil_camp_chall.dta", clear
	
		* gini
		eststo reg_median_c_gini_chal: quietly areg camp_exp_pc before above_median_corrupt median_before before_gini $muni_controls $challenger_controls i.term, absorb(codigo_uf) robust  cluster($cluster)
				sum camp_exp_pc if e(sample), mean 
				loc mymean: display %9.3f r(mean) 	
				estadd local mD `mymean', replace	
				estadd local state_fe "\checkmark": reg_median_c_gini_chal
				estadd local mayor_municipal "\checkmark": reg_median_c_gini_chal
				lincom before + median_before
				local estimate: display %9.3f r(estimate)
				local p_test: display %9.3f r(p)
				estadd local b0_b2 `estimate': reg_median_c_gini_chal
				estadd local p_value `p_test': reg_median_c_gini_chal

		* pib
		eststo reg_median_c_pib_chal: quietly areg camp_exp_pc before above_median_corrupt median_before before_lpib_pc $muni_controls $challenger_controls i.term, absorb(codigo_uf) robust  cluster($cluster)
				sum camp_exp_pc if e(sample), mean 
				loc mymean: display %9.3f r(mean) 	
				estadd local mD `mymean', replace	
				estadd local state_fe "\checkmark": reg_median_c_pib_chal
				estadd local mayor_municipal "\checkmark": reg_median_c_pib_chal
				lincom before + median_before
				local estimate: display %9.3f r(estimate)
				local p_test: display %9.3f r(p)
				estadd local b0_b2 `estimate': reg_median_c_pib_chal
				estadd local p_value `p_test': reg_median_c_pib_chal
		
		* illiteracy
		eststo reg_median_c_illi_chal: quietly areg camp_exp_pc before above_median_corrupt median_before before_illiteracy $muni_controls $challenger_controls i.term, absorb(codigo_uf) robust  cluster($cluster)
				sum camp_exp_pc if e(sample), mean 
				loc mymean: display %9.3f r(mean) 	
				estadd local mD `mymean', replace	
				estadd local state_fe "\checkmark": reg_median_c_illi_chal
				estadd local mayor_municipal "\checkmark": reg_median_c_illi_chal
				lincom before + median_before
				local estimate: display %9.3f r(estimate)
				local p_test: display %9.3f r(p)
				estadd local b0_b2 `estimate': reg_median_c_illi_chal
				estadd local p_value `p_test': reg_median_c_illi_chal
				
		* all
		eststo reg_median_c_all_chal: quietly areg camp_exp_pc before above_median_corrupt median_before before_gini before_lpib_pc before_illiteracy $muni_controls $challenger_controls i.term, absorb(codigo_uf) robust  cluster($cluster)
				sum camp_exp_pc if e(sample), mean 
				loc mymean: display %9.3f r(mean) 	
				estadd local mD `mymean', replace	
				estadd local state_fe "\checkmark": reg_median_c_all_chal
				estadd local mayor_municipal "\checkmark": reg_median_c_all_chal
				lincom before + median_before
				local estimate: display %9.3f r(estimate)
				local p_test: display %9.3f r(p)
				estadd local b0_b2 `estimate': reg_median_c_all_chal
				estadd local p_value `p_test': reg_median_c_all_chal
										
										
restore									
				

	
* EXPORT TABLE TO LATEX		
		#delimit;
			esttab reg_median_c_gini reg_median_c_pib reg_median_c_illi reg_median_c_all
					reg_median_c_gini_chal reg_median_c_pib_chal reg_median_c_illi_chal reg_median_c_all_chal
			using "tables and figures/table_c7.tex", b(3) se compress label star(* 0.10 ** 0.05 *** 0.01) replace
			keep(before median_before above_median_corrupt before_gini before_lpib_pc before_illiteracy  ) 
			/*scalars("mayor_municipal Mayor and municipal controls" "state_fe State fixed effects")  */
			mgroups( "Incumbent"   "Challenger"  , pattern(1 0 0 0 1 0 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) 
			stats(N mD mayor_municipal state_fe r2_a b0_b2 p_value, fmt(%9.0fc %9.3fc ) labels("Observations" "Dep. Var. Mean" "Mayor and municipal controls" "State and term FE" "Adjusted R$^2$" "$\beta_0+\beta_2 \, c_{ist}$" "p-value"))
			/*nonum*/ ar2 booktabs nonotes nomtitles title(deletethis) 
			substitute(\begin{table}[htbp]\centering \centering \caption{deletethis} /*\footnotesize*/{ \end{tabular} \end{tabular}} \end{table} %);
		#delimit cr
			


			
* Table C.8 
capture gen before_male = before * male
capture gen before_married = before * married
capture gen before_age = before * age
capture gen before_education = before * education
capture gen before_prev_mayor = before * prev_mayor

	label var before_male "Before $\times$ Male"
	label var before_married "Before $\times$ Married"	
	label var before_age "Before $\times$ Age"
	label var before_education "Before $\times$ Education"
	label var before_prev_mayor "Before $\times$ Previous Mayor"
	
eststo clear	
		* male
		eststo reg_median_c_male: quietly areg camp_exp_pc before above_median_corrupt median_before before_male $muni_controls $mayor_controls i.term, absorb(codigo_uf) robust  cluster($cluster)
				sum camp_exp_pc if e(sample), mean 
				loc mymean: display %9.3f r(mean) 	
				estadd local mD `mymean', replace	
				estadd local state_fe "\checkmark": reg_median_c_male
				estadd local mayor_municipal "\checkmark": reg_median_c_male
				lincom before + median_before
				local estimate: display %9.3f r(estimate)
				local p_test: display %9.3f r(p)
				estadd local b0_b2 `estimate': reg_median_c_male
				estadd local p_value `p_test': reg_median_c_male

		* married
		eststo reg_median_c_married: quietly areg camp_exp_pc before above_median_corrupt median_before before_married $muni_controls $mayor_controls i.term, absorb(codigo_uf) robust  cluster($cluster)
				sum camp_exp_pc if e(sample), mean 
				loc mymean: display %9.3f r(mean) 	
				estadd local mD `mymean', replace	
				estadd local state_fe "\checkmark": reg_median_c_married
				estadd local mayor_municipal "\checkmark": reg_median_c_married
				lincom before + median_before
				local estimate: display %9.3f r(estimate)
				local p_test: display %9.3f r(p)
				estadd local b0_b2 `estimate': reg_median_c_married
				estadd local p_value `p_test': reg_median_c_married				
				
		* age
		eststo reg_median_c_age: quietly areg camp_exp_pc before above_median_corrupt median_before before_age $muni_controls $mayor_controls i.term, absorb(codigo_uf) robust  cluster($cluster)
				sum camp_exp_pc if e(sample), mean 
				loc mymean: display %9.3f r(mean) 	
				estadd local mD `mymean', replace	
				estadd local state_fe "\checkmark": reg_median_c_age
				estadd local mayor_municipal "\checkmark": reg_median_c_age
				lincom before + median_before
				local estimate: display %9.3f r(estimate)
				local p_test: display %9.3f r(p)
				estadd local b0_b2 `estimate': reg_median_c_age
				estadd local p_value `p_test': reg_median_c_age
		
		* Education
		eststo reg_median_c_educ: quietly areg camp_exp_pc before above_median_corrupt median_before before_education $muni_controls $mayor_controls i.term, absorb(codigo_uf) robust  cluster($cluster)
				sum camp_exp_pc if e(sample), mean 
				loc mymean: display %9.3f r(mean) 	
				estadd local mD `mymean', replace	
				estadd local state_fe "\checkmark": reg_median_c_educ
				estadd local mayor_municipal "\checkmark": reg_median_c_educ
				lincom before + median_before
				local estimate: display %9.3f r(estimate)
				local p_test: display %9.3f r(p)
				estadd local b0_b2 `estimate': reg_median_c_educ
				estadd local p_value `p_test': reg_median_c_educ
				
		* Previous Mayor
		eststo reg_median_c_prev_may: quietly areg camp_exp_pc before above_median_corrupt median_before before_prev_mayor $muni_controls $mayor_controls i.term, absorb(codigo_uf) robust  cluster($cluster)
				sum camp_exp_pc if e(sample), mean 
				loc mymean: display %9.3f r(mean) 	
				estadd local mD `mymean', replace	
				estadd local state_fe "\checkmark": reg_median_c_prev_may
				estadd local mayor_municipal "\checkmark": reg_median_c_prev_may
				lincom before + median_before
				local estimate: display %9.3f r(estimate)
				local p_test: display %9.3f r(p)
				estadd local b0_b2 `estimate': reg_median_c_prev_may
				estadd local p_value `p_test': reg_median_c_prev_may
										
		* All
		eststo reg_median_c_may_all: quietly areg camp_exp_pc before above_median_corrupt median_before before_male before_married before_age before_education before_prev_mayor $muni_controls $mayor_controls i.term, absorb(codigo_uf) robust  cluster($cluster)
				sum camp_exp_pc if e(sample), mean 
				loc mymean: display %9.3f r(mean) 	
				estadd local mD `mymean', replace	
				estadd local state_fe "\checkmark": reg_median_c_may_all
				estadd local mayor_municipal "\checkmark": reg_median_c_may_all
				lincom before + median_before
				local estimate: display %9.3f r(estimate)
				local p_test: display %9.3f r(p)
				estadd local b0_b2 `estimate': reg_median_c_may_all
				estadd local p_value `p_test': reg_median_c_may_all

		#delimit;
			esttab  reg_median_c_male reg_median_c_married reg_median_c_age reg_median_c_educ reg_median_c_prev_may reg_median_c_may_all
			using "tables and figures/table_c8.tex", b(3) se compress label star(* 0.10 ** 0.05 *** 0.01) replace
			keep(before median_before above_median_corrupt before_male before_married before_age before_education before_prev_mayor ) 
			mgroups( "Incumbent"  , pattern(1 0 0 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) 
			stats(N mD mayor_municipal state_fe r2_a b0_b2 p_value, fmt(%9.0fc %9.3fc ) labels("Observations" "Dep. Var. Mean" "Mayor and municipal controls" "State and term FE" "Adjusted R$^2$" "$\beta_0+\beta_2 \, c_{ist}$" "p-value"))
			/*nonum*/ ar2 booktabs nonotes nomtitles title(deletethis) 
			substitute(\begin{table}[htbp]\centering \centering \caption{deletethis} /*\footnotesize*/{ \end{tabular} \end{tabular}} \end{table} %);
		#delimit cr

* Table C9
	tabstat month0_3 month3_12 month12_n, by(term) statistics(sum) format(%9.0f)  	  
	gen after = 1-before
	label var after "After the election"

	eststo clear	
	bysort term: eststo: estpost summarize month0_3 month3_12 month12_n after if camp_exp_pc !=., listwise 
	esttab using "tables and figures\table_c9.tex", cells("sum(fmt(0))   mean(fmt(3))  ") label nodepvar /*
	*/ mgroups( "Term 2001-2004"   "Term 2005-2008"  , pattern(1 1) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) /* 
	*/  nomtitle  nonumber replace			

	
* Table C10. 			
* Release election 	
		eststo reg_broad_basic: quietly areg camp_exp_pc month0_3 month3_12 month12_n i.term , absorb(codigo_uf) robust cluster($cluster)
				sum camp_exp_pc if e(sample), mean 
				loc mymean: display %9.3f r(mean) 	
				estadd local mD `mymean', replace	
				estadd local state_fe "\checkmark": reg_broad_basic

		eststo reg_broad_basic_c: quietly areg camp_exp_pc month0_3 month3_12 month12_n $muni_controls $mayor_controls i.term , absorb(codigo_uf) robust cluster($cluster)
				sum camp_exp_pc if e(sample), mean 
				loc mymean: display %9.3f r(mean) 	
				estadd local mD `mymean', replace	
				estadd local state_fe "\checkmark": reg_broad_basic_c
				estadd local mayor_municipal "\checkmark": reg_broad_basic_c

		eststo reg_median: quietly areg camp_exp_pc month0_3 month3_12 month12_n above_median_corrupt median_month0_3 median_month3_12 median_year12_n i.term, absorb(codigo_uf) robust  cluster($cluster)
				sum camp_exp_pc if e(sample), mean 
				loc mymean: display %9.3f r(mean) 	
				estadd local mD `mymean', replace	
				estadd local state_fe "\checkmark": reg_median
				
				lincom month0_3 + median_month0_3
				local estimate: display %9.3f r(estimate)
				local p_test: display %9.3f r(p)
				estadd local b0_b2_0 `estimate': reg_median
				estadd local p_value `p_test': reg_median

				lincom month3_12 + median_month3_12
				local estimate: display %9.3f r(estimate)
				local p_test: display %9.3f r(p)
				estadd local b0_b2_3 `estimate': reg_median
				estadd local p_value3 `p_test': reg_median

				lincom month12_n + median_year12_n
				local estimate: display %9.3f r(estimate)
				local p_test: display %9.3f r(p)
				estadd local b0_b2_12 `estimate': reg_median
				estadd local p_value12 `p_test': reg_median

		eststo reg_median_c: quietly areg camp_exp_pc month0_3 month3_12 month12_n above_median_corrupt median_month0_3 median_month3_12 median_year12_n $muni_controls $mayor_controls i.term, absorb(codigo_uf) robust  cluster($cluster)
				sum camp_exp_pc if e(sample), mean 
				loc mymean: display %9.3f r(mean) 	
				estadd local mD `mymean', replace	
				estadd local state_fe "\checkmark": reg_median_c
				estadd local mayor_municipal "\checkmark": reg_median_c
				
				lincom month0_3 + median_month0_3
				local estimate: display %9.3f r(estimate)
				local p_test: display %9.3f r(p)
				estadd local b0_b2_0 `estimate': reg_median_c
				estadd local p_value `p_test': reg_median_c

				lincom month3_12 + median_month3_12
				local estimate: display %9.3f r(estimate)
				local p_test: display %9.3f r(p)
				estadd local b0_b2_3 `estimate': reg_median_c
				estadd local p_value3 `p_test': reg_median_c

				lincom month12_n + median_year12_n
				local estimate: display %9.3f r(estimate)
				local p_test: display %9.3f r(p)
				estadd local b0_b2_12 `estimate': reg_median_c
				estadd local p_value12 `p_test': reg_median_c



		#delimit;
			esttab reg_broad_basic reg_broad_basic_c reg_median reg_median_c
			using "tables and figures\table_c10.tex", b(3) se compress label star(* 0.10 ** 0.05 *** 0.01) replace
			mgroups( "\shortstack{Information \\ disclosure}""\shortstack{Median \\ Corruption}"     , pattern(1 0 1 0  ) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) 
			keep(month0_3 month3_12 month12_n above_median_corrupt median_month0_3 median_month3_12 median_year12_n ) 
			stats(N mD mayor_municipal state_fe r2_a b0_b2_0 p_value b0_b2_3 p_value3 b0_b2_12 p_value12, fmt(%9.0fc %9.3fc ) labels("Observations" "Dep. Var. Mean" "Mayor and municipal controls" "State and term FE" "Adjusted R$^2$" "$\beta_0+\beta_2 \, c_{ist}$ ($<$ 3 months)" "p-value"  "$\beta_0+\beta_2 \, c_{ist}$ (3 to 12 months)" "p-value"  "$\beta_0+\beta_2 \, c_{ist}$ ($>$ 12 months)" "p-value" ))
			/*nonum*/ ar2 booktabs nonotes nomtitles title(deletethis) 
			substitute(\begin{table}[htbp]\centering \centering \caption{deletethis} /*\footnotesize*/{ \end{tabular} \end{tabular}} \end{table} %);
		#delimit cr

					
* Table c11 in "analysis_polls.do"
* Table c12 in "analysis_polls.do"


* Table c.13
* Regressions Bolsa Familia
	global BEFORE before
	global corrupt broad	
	local Other_reg "bolsa_pc valor"
	foreach dep_var of varlist `Other_reg' {
	  
			eststo m_c_`dep_var': quietly areg `dep_var' $BEFORE above_median_corrupt median_before $muni_controls $mayor_controls i.term if rerun == 1, absorb(codigo_uf) robust  cluster(id_city)
				sum `dep_var' if e(sample), mean 
				loc mymean: display %9.3f r(mean) 	
				estadd local mD `mymean', replace	
				estadd local state_fe "\checkmark": m_c_`dep_var'
				estadd local mayor_municipal "\checkmark": m_c_`dep_var'
				* Add Test interactions
				lincom $BEFORE + median_before
				local estimate: display %9.3f r(estimate)
				local p_test: display %9.3f r(p)
				estadd local b0_b2 `estimate': m_c_`dep_var'
				estadd local p_value `p_test': m_c_`dep_var'

			eststo q_c_`dep_var': quietly areg `dep_var' $BEFORE quartile2 quartile3 quartile4 quart2_before quart3_before quart4_before $muni_controls $mayor_controls i.term if rerun == 1, absorb(codigo_uf) robust  cluster(id_city)
				sum `dep_var' if e(sample), mean 
				loc mymean: display %9.3f r(mean) 	
				estadd local mD `mymean', replace	
				estadd local state_fe "\checkmark": q_c_`dep_var'
				estadd local mayor_municipal "\checkmark": q_c_`dep_var'
				* Add Test interactions
				lincom $BEFORE + quart4_before
				local estimate: display %9.3f r(estimate)
				local p_test: display %9.3f r(p)
				estadd local b0_b2 `estimate': q_c_`dep_var'
				estadd local p_value `p_test': q_c_`dep_var'								
	}
	
* Regressions Public Employment
preserve
capture gen Before_1 = before_1
	replace Before_1 = 1 if Before_1 == 0 &  lottery == 25 & term ==2005 
	label var Before_1 "Lottery occurred before the year previous of the election."

	replace before = Before_1
	global BEFORE before
	global corrupt broad
	local Other_reg "empl_perm_pc empl_trans_pc"
		
	foreach dep_var of varlist `Other_reg' {
	    
			eststo m_c_`dep_var': quietly areg `dep_var' $BEFORE above_median_corrupt median_before $muni_controls $mayor_controls i.term if rerun == 1, absorb(codigo_uf) robust  cluster(id_city)
				sum `dep_var' if e(sample), mean 
				loc mymean: display %9.3f r(mean) 	
				estadd local mD `mymean', replace	
				estadd local state_fe "\checkmark": m_c_`dep_var'
				estadd local mayor_municipal "\checkmark": m_c_`dep_var'
				* Add Test interactions
				lincom $BEFORE + median_before
				local estimate: display %9.3f r(estimate)
				local p_test: display %9.3f r(p)
				estadd local b0_b2 `estimate': m_c_`dep_var'
				estadd local p_value `p_test': m_c_`dep_var'
	
			eststo q_c_`dep_var': quietly areg `dep_var' $BEFORE quartile2 quartile3 quartile4 quart2_before quart3_before quart4_before $muni_controls $mayor_controls i.term if rerun == 1, absorb(codigo_uf) robust  cluster(id_city)
				sum `dep_var' if e(sample), mean 
				loc mymean: display %9.3f r(mean) 	
				estadd local mD `mymean', replace	
				estadd local state_fe "\checkmark": q_c_`dep_var'
				estadd local mayor_municipal "\checkmark": q_c_`dep_var'
				* Add Test interactions
				lincom $BEFORE + quart4_before
				local estimate: display %9.3f r(estimate)
				local p_test: display %9.3f r(p)
				estadd local b0_b2 `estimate': q_c_`dep_var'
				estadd local p_value `p_test': q_c_`dep_var'								
	}
	
restore
	
  eststo dir
	  
		#delimit;
		esttab 
			m_c_bolsa_pc q_c_bolsa_pc m_c_valor q_c_valor 
			m_c_empl_perm_pc q_c_empl_perm_pc m_c_empl_trans_pc q_c_empl_trans_pc
			using "tables and figures\table_c13.tex", b(3) se compress label star(* 0.10 ** 0.05 *** 0.01) replace
			mtitles( "Median" "Quartile"  "Median" "Quartile" "Median" "Quartile" "Median" "Quartile") 
			mgroups( "\shortstack{Beneficiary families \\(\% population)}"   "Value of benefits" "Permanent employees" "Transitory employees"  , pattern(1 0 1 0 1 0 1 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) 
			keep($BEFORE above_median_corrupt median_before 
				 quart2_before quart3_before quart4_before quartile2 quartile3 quartile4)
			stats(N mD r2_a b0_b2 p_value, fmt(%9.0fc %9.3fc ) labels("Observations" "Dep. Var. Mean" "Adjusted R$^2$" "$\beta_0+\beta_2 \, c_{ist}$" "p-value"))
			/*nonum*/ ar2 booktabs nonotes /*nomtitles*/ title(deletethis) 
			substitute(\begin{table}[htbp]\centering \centering \caption{deletethis} /*\footnotesize*/{ \end{tabular} \end{tabular}} \end{table} %);
		#delimit cr


* table c14	in "analysis_extras.do"
* table c15 in "analysis_extras.do"
* Table c16	in "analysis_extras.do"
* Table c17 in "analysis_extras.do"


* Figure c1
histogram camp_exp_pc, freq 
	graph export "tables and figures\figure_c1a.pdf", replace 

preserve
use "data_brasil_camp_chall.dta", clear
histogram camp_exp_pc, freq 
	graph export "tables and figures\figure_c1b.pdf", replace
restore

* Figure c2 in "analysis_polls.do"

eststo clear		